*************** Preamble
***************
***************

***Set Stata options
clear 
cap clear matrix
cap clear mata
set more off
cap set mat 800
cap set mem 500m

***Set directories
global maindirectory C:\Users\Dropbox\Papers /*Update path to relevant working directory*/
global data $maindirectory\Data\Clean Data\
global output $maindirectory\Output\

***Output options
global outopts st(coef se pval) paren(se) br(pval) bdec(3) nocon excel

*************** Table 2: Credible Budgets and Wartime Spending
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset countrycode year

cap erase table2.txt
cap erase table2.xml
	*Column 1: Benchmark
xi: xtreg logexppercap budget extwar interactionBE l.intwar l.urbanrate i.year, fe vce(cl countrycode)
		outreg2 using table2, keep(budget extwar interactionBE l.intwar l.urbanrate) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, No, Country trend, No, Cluster, Country) append
	*Column 2: Add region trends
xi: xtreg logexppercap budget extwar interactionBE l.intwar l.urbanrate i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using table2, keep(budget extwar interactionBE l.intwar l.urbanrate) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Country trend, No, Cluster, Country) append
	*Column 3: Add country trends
xi: xtreg logexppercap budget extwar interactionBE l.intwar l.urbanrate i.year countrytrend*, fe vce(cl countrycode)
		outreg2 using table2, keep(budget extwar interactionBE l.intwar l.urbanrate) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, No, Country trend, Yes, Cluster, Country) append
cap erase table2.txt

*************** Table A1: Credible Budgets and Tax Extraction
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset countrycode year

cap erase tableA1.txt
cap erase tableA1.xml
	*Column 1: Benchmark
xi: xtreg logrevpercap budget i.year, fe vce(cl countrycode)
		outreg2 using tableA1, keep(budget) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, No, Region trend, No, Cluster, Country) append
	*Column 2: Add controls
xi: xtreg logrevpercap budget l.extwar l.intwar l.urbanrate i.year, fe vce(cl countrycode)
		outreg2 using tableA1, keep(budget l.extwar l.intwar l.urbanrate) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, No, Cluster, Country) append
	*Column 3: Controls + region trends
xi: xtreg logrevpercap budget l.extwar l.intwar l.urbanrate i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA1, keep(budget l.extwar l.intwar l.urbanrate) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
cap erase tableA1.txt

*************** Table A2: Credible Budgets and Sovereign Bond Yields
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset countrycode year

cap erase tableA2.txt
cap erase tableA2.xml
	*Column 1: Benchmark
xi: xtreg yield budget i.year, fe vce(cl countrycode)
		outreg2 using tableA2, keep(budget) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, No, Region trend, No, Cluster, Country) append
	*Column 2: Add controls
xi: xtreg yield budget l.extwar l.intwar l.urbanrate i.year, fe vce(cl countrycode)
		outreg2 using tableA2, keep(budget l.extwar l.intwar l.urbanrate) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, No, Cluster, Country) append
	*Column 3: Controls + region trends
xi: xtreg yield budget l.extwar l.intwar l.urbanrate i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA2, keep(budget l.extwar l.intwar l.urbanrate) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
cap erase tableA2.txt

*************** Table A3: Sample Wars, Years, and Coalitions
***************
***************
*See "cd_table_WarsYearsCoalitions_jop.do" for do-file
*See "cd_table_WarsYearsCoalitions_clean_jop.dta" for output

*************** Table A4: Dynastic Fixed Effects
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset dynastycode year

cap erase tableA4.txt
cap erase tableA4.xml
	*Column 1: Benchmark + region trends
xi: xtreg logexppercap budget extwar interactionBE l.intwar l.urbanrate i.year regiontrend*, fe vce(cl dynastycode)
		outreg2 using tableA4, keep(budget extwar interactionBE l.intwar l.urbanrate) $outopts ///
		addtext(Dynasty FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Dynasty) append
	*Column 2: Include majorwar + interactionBM
xi: xtreg logexppercap budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate i.year regiontrend*, fe vce(cl dynastycode)
		outreg2 using tableA4, keep(budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate) $outopts ///
		addtext(Dynasty FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Dynasty) append
cap erase tableA4.txt

*************** Table A5: Opponent Strength
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset countrycode year

cap erase tableA5.txt
cap erase tableA5.xml
	*Column 1: Oppogdp
xi: xtreg logexppercap budget logoppogdp interactionBG l.intwar l.urbanrate i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA5, keep(budget logoppogdp interactionBG l.intwar l.urbanrate) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
	*Column 2: Oppopop
xi: xtreg logexppercap budget logoppopop interactionBO l.intwar l.urbanrate i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA5, keep(budget logoppopop interactionBO l.intwar l.urbanrate) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
cap erase tableA5.txt

*************** Table A6: War Size
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset countrycode year

cap erase tableA6.txt
cap erase tableA6.xml
	*Column 1: Include majorwar + interactionBM
xi: xtreg logexppercap budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA6, keep(budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
cap erase tableA6.txt

*************** Table A7: Suffrage
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset countrycode year

cap erase tableA7.txt
cap erase tableA7.xml
	*Column 1: Scheve-Stasavage 2012: Benchmark + region trends
xi: xtreg logexppercap budget extwar interactionBE l.intwar l.urbanrate suffrage_scst i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA7, keep(budget extwar interactionBE l.intwar l.urbanrate suffrage_scst) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
	*Column 2: Scheve-Stasavage 2012: Include majorwar + interactionBM
xi: xtreg logexppercap budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate suffrage_scst i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA7, keep(budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate suffrage_scst) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
	*Column 3: V-Dem v9: Benchmark + region trends
xi: xtreg logexppercap budget extwar interactionBE l.intwar l.urbanrate suffrage_vdem i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA7, keep(budget extwar interactionBE l.intwar l.urbanrate suffrage_vdem) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
	*Column 4: V-Dem v9: Include majorwar + interactionBM
xi: xtreg logexppercap budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate suffrage_vdem i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA7, keep(budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate suffrage_vdem) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
	*Column 5: LIED v4: Benchmark + region trends
xi: xtreg logexppercap budget extwar interactionBE l.intwar l.urbanrate suffrage_lied i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA7, keep(budget extwar interactionBE l.intwar l.urbanrate suffrage_lied) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
	*Column 6: LIED v4: Include majorwar + interactionBM
xi: xtreg logexppercap budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate suffrage_lied i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA7, keep(budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate suffrage_lied) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
cap erase tableA7.txt

*************** Table A8: Exclude Countries One by One
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

levelsof countryname, local(vals)

xtset countrycode year

cap erase tableA8.txt
cap erase tableA8.xml
	*Columns 1-10: Benchmark + region trends
foreach i of local vals {
xi: xtreg logexppercap budget extwar interactionBE l.intwar l.urbanrate i.year regiontrend* if countryname!="`i'", fe vce(cl countrycode)
		outreg2 using tableA8, keep(budget extwar interactionBE l.intwar l.urbanrate ) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country, Sample, No `i') append
		}
cap erase tableA8.txt

*************** Table A9: Lagged Dependent Variable
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset countrycode year

cap erase tableA9.txt
cap erase tableA9.xml
		*Column 1: Benchmark + region trends
xi: xtreg logexppercap budget extwar interactionBE l.intwar l.urbanrate l.logexppercap i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA9, keep(budget extwar interactionBE l.intwar l.urbanrate l.logexppercap) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
	*Column 2: Include majorwar + interactionBM
xi: xtreg logexppercap budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate l.logexppercap i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA9, keep(budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate l.logexppercap) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
cap erase tableA9.txt

*************** Table A10: Central Banks
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset countrycode year

cap erase tableA10.txt
cap erase tableA10.xml
	*Column 1: Benchmark + region trends
xi: xtreg logexppercap budget extwar interactionBE l.intwar l.urbanrate centralbank i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA10, keep(budget extwar interactionBE l.intwar l.urbanrate centralbank) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
	*Column 2: Include majorwar + interactionBM
xi: xtreg logexppercap budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate centralbank i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA10, keep(budget extwar interactionBE majorwar interactionBM l.intwar l.urbanrate centralbank) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
cap erase tableA10.txt

*************** Table A11: GDP per capita
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset countrycode year

cap erase tableA11.txt
cap erase tableA11.xml
		*Column 1: Benchmark + region trends
xi: xtreg logexppercap budget extwar interactionBE l.intwar l.loggdppercap i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA11, keep(budget extwar interactionBE l.intwar l.loggdppercap) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
	*Column 2: Include majorwar + interactionBM
xi: xtreg logexppercap budget extwar interactionBE majorwar interactionBM l.intwar l.loggdppercap i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA11, keep(budget extwar interactionBE majorwar interactionBM l.intwar l.loggdppercap) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
cap erase tableA11.txt

*************** Table A12: Revolution
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset countrycode year

cap erase tableA12.txt
cap erase tableA12.xml
		*Column 1: Benchmark + region trends
xi: xtreg logexppercap budget extwar interactionBE l.revolution l.intwar_other l.urbanrate i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA12, keep(budget extwar interactionBE l.revolution l.intwar_other l.urbanrate) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
	*Column 2: Include majorwar + interactionBM
xi: xtreg logexppercap budget extwar interactionBE majorwar interactionBM l.revolution l.intwar_other l.urbanrate i.year regiontrend*, fe vce(cl countrycode)
		outreg2 using tableA12, keep(budget extwar interactionBE majorwar interactionBM l.revolution l.intwar_other l.urbanrate) $outopts ///
		addtext(Country FE, Yes, Year FE, Yes, Controls, Yes, Region trend, Yes, Cluster, Country) append
cap erase tableA12.txt

*************** Figure 2: England's Revenue Advantage over France
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

*Restrict sample
keep if year>=1660 & year<=1730
keep if countryname=="england" | countryname=="france"

*Make underlying variables
gen revpercap=exp(logrevpercap)
gen revpercap_eng=revpercap if countryname=="england"
gen revpercap_fra=revpercap if countryname=="france"

bysort year: gen N_n=_n==1 
bysort year: egen revpercap_eng_max=max(revpercap_eng) 
bysort year: egen revpercap_fra_max=max(revpercap_fra) 
drop if N_n==0

drop revpercap_eng revpercap_fra
rename revpercap_eng_max revpercap_eng
rename revpercap_fra_max revpercap_fra

*Make variable of interest
gen revpercapdiff=revpercap_eng-revpercap_fra

*Make figure
twoway (scatter revpercapdiff year, msymbol(circle_hollow) mlcolor(black)) ///
	(lowess revpercapdiff year if year<=1688, lpattern(solid) lwidth(medthick) lcolor(red)) ///
	(lowess revpercapdiff year if year>=1688, lpattern(solid) lwidth(medthick) lcolor(blue)) ///) ///
	, scheme(lean1) ///
	title() ///
	xline(1688, lpattern(dash) lcolor(black)) ///
	xlabel(1660(10)1730) ///
	xtick(1660(10)1730) ///
	xmtick(1660(5)1730) ///
	xtitle("") ///
	ymtick(-2(1)5) ///
	ylabel(-2(1)5, format(%9.0f)) ///
	ytitle(Revenue advantage (per capita)) ///
	legend(off)
graph export figure2.png, as(png) width(2500) replace
cap graph close graph

*************** Figure A1: Deviation from Mean Expenditures Prior to Pre-Budgetary Reform
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

*Restrict data and make relevant variables
drop if budget==1
bysort countryname (year): gen lastten= _n > (_N - 10)
keep if lastten

bysort countryname (year): gen row = _n - 11
sort row

gen exppercap=exp(logexppercap)
egen meanexp = mean(exppercap), by(row)
gen expdeviation=exppercap-meanexp

*Make figure
twoway (connected expdeviation row if countryname=="austria", msymbol(circle_hollow) mlcolor(black)) ///
       (connected expdeviation row if countryname=="denmark", msymbol(circle_hollow) mlcolor(black)) ///
       (connected expdeviation row if countryname=="england", msymbol(circle_hollow) mlcolor(black)) ///
       (connected expdeviation row if countryname=="france", msymbol(circle_hollow) mlcolor(black)) ///
       (connected expdeviation row if countryname=="netherlands", msymbol(circle_hollow) mlcolor(black)) ///
       (connected expdeviation row if countryname=="piedmont", msymbol(circle_hollow) mlcolor(black)) ///
       (connected expdeviation row if countryname=="portugal", msymbol(circle_hollow) mlcolor(black)) ///
       (connected expdeviation row if countryname=="prussia", msymbol(circle_hollow) mlcolor(black)) ///
       (connected expdeviation row if countryname=="spain", msymbol(circle_hollow) mlcolor(black)) ///
       (connected expdeviation row if countryname=="sweden", msymbol(circle_hollow) mlcolor(black)) ///
        , scheme(lean1) ///
        title() ///
        xlabel(-10(1)-1) ///
        xtick(-10(1)-1) ///
        xtitle(10-year period prior to budgetary reform) ///
        ylabel(-10(5)15, format(%9.0f)) ///
        ytick(-10(5)15) ///
        ytitle(Deviation from mean (per cap expenditure)) ///
        legend(off)
graph export figureA1.png, as(png) width(2500) replace
cap graph close graph

*************** Section 3: Descriptive Statistics for War of Grand Alliance (1688-97)
***************
***************
*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

*Make log
cap log close
log using "section3_descriptive_stats", text replace

*Make underlying variables
gen exppercap=exp(logexppercap)
gen expgross=exppercap*pop

gen revpercap=exp(logrevpercap)
gen revgross=revpercap*pop

*Make variable of interest
gen loanpercap=(expgross-revgross)/pop

*Decade before war
summ loanpercap if countryname=="england" & year>=1679 & year<1688
summ loanpercap if countryname=="france" & year>=1679 & year<1688

*During war (post-Glorious Revolution)
summ loanpercap if countryname=="england" & year>=1689 & year<=1697
summ loanpercap if countryname=="france" & year>=1689 & year<=1697

log close

*************** Footnotes
***************
***************
*Make log
cap log close
log using "footnotes_results", text replace

*Dynastic Fixed Effects: Tax Extraction

*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset dynastycode year

	*Benchmark
xi: xtreg logrevpercap budget i.year, fe vce(cl dynastycode)
	*Add controls
xi: xtreg logrevpercap budget l.extwar l.intwar l.urbanrate i.year, fe vce(cl dynastycode)
	*Controls + region trends
xi: xtreg logrevpercap budget l.extwar l.intwar l.urbanrate i.year regiontrend*, fe vce(cl dynastycode)

*Dynastic Fixed Effects: Sovereign Bond Yields

	*Benchmark
xi: xtreg yield budget i.year, fe vce(cl dynastycode)
	*Add controls
xi: xtreg yield budget l.extwar l.intwar l.urbanrate i.year, fe vce(cl dynastycode)
	*Controls + region trends
xi: xtreg yield budget l.extwar l.intwar l.urbanrate i.year regiontrend*, fe vce(cl dynastycode)

*Suffrage: Tax Extraction

*Load data
cd "$data"
use "cd_exp_panel_jop", clear
cd "$output"

xtset countrycode year

	*Benchmark
xi: xtreg logrevpercap budget suffrage_scst i.year, fe vce(cl countrycode)
	*Add controls
xi: xtreg logrevpercap budget l.extwar l.intwar l.urbanrate suffrage_scst i.year, fe vce(cl countrycode)
	*Controls + region trends
xi: xtreg logrevpercap budget l.extwar l.intwar l.urbanrate suffrage_scst i.year regiontrend*, fe vce(cl countrycode)

*Suffrage: Sovereign Bond Yields

	*Benchmark
xi: xtreg yield budget suffrage_scst i.year, fe vce(cl countrycode)
	*Add controls
xi: xtreg yield budget l.extwar l.intwar l.urbanrate suffrage_scst i.year, fe vce(cl countrycode)
	*Controls + region trends
xi: xtreg yield budget l.extwar l.intwar l.urbanrate suffrage_scst i.year regiontrend*, fe vce(cl countrycode)

log close
